/*
 * [文 件 名]:B5MNetworkUtils.java
 * [创 建 人]:allenwang
 * [创建时间]:Apr 3, 2014
 * [编　　码]:UTF-8
 * [版　　权]:Copyright © 2012 B5Msoft Co,Ltd. 
 */

package com.sfdlJPush.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;

import com.sfdlJPush.controller.MainApplication;

/**
 * [简要描述]: [详细描述]:
 * 
 * @author [allenwang]
 * @email [allen.wang@b5m.com]
 * @version [版本号,Apr 3, 2014]
 * @see [B5MNetworkUtils]
 * @package [com.plus.core.api]
 * @since [PLUSCore]
 */
public class B5MNetworkUtils
{
    public static final int NETWORN_NONE = 0;
    public static final int NETWORN_WIFI = 1;
    public static final int NETWORN_MOBILE = 2;
    public static int CURRENT_NETWORK = 0;

    public static int getNetworkState(Context context)
    {
        ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        // Wifi
        State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
        if (state == State.CONNECTED || state == State.CONNECTING)
            return NETWORN_WIFI;
        // 3G
        state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
        if (state == State.CONNECTED || state == State.CONNECTING)
            return NETWORN_MOBILE;
        return NETWORN_NONE;
    }

    public static boolean isNetworkAvailabel()
    {
        return (B5MNetworkUtils.NETWORN_NONE != B5MNetworkUtils.CURRENT_NETWORK);
    }

    public static boolean isNetworkAvailabelAddition()
    {
        CURRENT_NETWORK = getNetworkState(MainApplication.getInstance());
        return (B5MNetworkUtils.NETWORN_NONE != B5MNetworkUtils.CURRENT_NETWORK);
    }
}
